define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_info/index' + location.search,
                    add_url: 'order_info/add',
                    edit_url: 'order_info/edit',
                    del_url: 'order_info/del',
                    multi_url: 'order_info/multi',
                    import_url: 'order_info/import',
                    table: 'order_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_no',
                sortName: 'order_no',
                fixedColumns: true,
                fixedRightNumber: 1,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')," 3":__('Status  3'),"4":__('Status 4'),"5":__('Status 5')," 10":__('Status  10')}, formatter: Table.api.formatter.status},
                        {field: 'order_total', title: __('Order_total'), operate:'BETWEEN'},
                        {field: 'order_num', title: __('Order_num')},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'order_desc', title: __('Order_desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'client_no', title: __('Client_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'client_name', title: __('Client_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'client_contact', title: __('Client_contact'), operate: 'LIKE'},
                        {field: 'saleman_name', title: __('Saleman_name'), operate: 'LIKE'},
                        //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
                        {
                            field: 'operate',
                            width: "150px",
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    title: __('商品明细'),
                                    extend: 'data-area=["1000px"]',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'order_info/detail',
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $('.btn-print').click(function () {
                var ids = Table.api.selectedids(table);//获取选中列的id
                Fast.api.open("order_info/printOrder?id=" + ids, __('打印订单'), {
                    area: ['100%', '100%']
                });
            })
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});